home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-08-01 | 2.0 KB | 104 lines | [TEXT/CWIE] |
- /*
- File: BSDFileLib.h
-
- Contains: Easy File Handling Routines.
-
- Version: Technology: Torture Chamber v1.0
- Package: BSDFileLib v1.0.2
-
- Copyright: © 1997, BuggySoft™ Development.
- By Scott Dunbar
- */
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __FILES__
- #include <Files.h>
- #endif
-
- #ifndef __FOLDERS__
- #include <Folders.h>
- #endif
-
- #ifndef _STDIO
- #include <stdio.h>
- #endif
-
- #ifndef _STRING
- #include <string.h>
- #endif
-
- #ifndef __BSDFILELIB_
- #include "BSDFileLib.h"
- #endif
-
- /*
- Name: ReadFile()
- Usage: ReadFile(vRefNum, dirID, fileName, fileData);
- */
-
- void ReadFile (short vRefNum, long dirID, Str31 name, Handle data) {
- FSSpec file;
- long byteCount;
- short refNum;
-
- if (FSMakeFSSpec(vRefNum, dirID, name, &file) != fnfErr) {
- FSpOpenDF(&file, fsRdPerm, &refNum);
- byteCount = GetHandleSize(data);
- HLock(data);
- FSRead(refNum, &byteCount, data);
- HUnlock(data);
- FSClose(refNum);
- }
- }
-
-
- /*
- Name: WriteFile()
- Usage: WriteFile(vRefNum, dirID, fileName, creatorType, fileType, fileData);
- */
-
- void WriteFile (short vRefNum, long dirID, Str31 name, OSType creatorType, OSType fileType, Handle data) {
- FSSpec file;
- long byteCount;
- short refNum;
-
- FSMakeFSSpec(vRefNum, dirID, name, &file);
- FSpCreate(&file, creatorType, fileType, smSystemScript);
- FSpOpenDF(&file, fsWrPerm, &refNum);
- byteCount = GetHandleSize(data);
- HLock(data);
- FSWrite(refNum, &byteCount, data);
- HUnlock(data);
- FSClose(refNum);
- }
-
-
- /*
- Name: ReadPrefsFile()
- Usage: ReadPrefsFile("\pMy Prefs", fileData);
- */
-
- void ReadPrefsFile (Str31 name, Handle data) {
- long dirID;
- short vRefNum;
-
- FindFolder(kOnSystemDisk, kPreferencesFolderType, true, &vRefNum, &dirID);
- ReadFile(vRefNum, dirID, name, data);
- }
-
-
- /*
- Name: WritePrefsFile()
- Usage: WritePrefsFile("\pMy Prefs", 'abcd', fileData);
- */
-
- void WritePrefsFile (Str31 name, OSType creatorType, Handle data) {
- long dirID;
- short vRefNum;
-
- FindFolder(kOnSystemDisk, kPreferencesFolderType, true, &vRefNum, &dirID);
- WriteFile(vRefNum, dirID, name, creatorType, kPreferencesFolderType, data);
- }